#import "AppDelegate.h"
#import "dfhgwhruebvhrheyleapoccurrenceViewController.h"
#import "dfhgwhruebvhrheyaltererroneousViewController.h"
#import "dfhgwhruebvhrheydisplayblastViewController.h"
@interface dfhgwhruebvhrheydisplayblastViewController ()<UIScrollViewDelegate>
@property (weak, nonatomic) IBOutlet UIView *containerView;
@property (weak, nonatomic) IBOutlet UIScrollView *scrollIV;
@property (weak, nonatomic) IBOutlet UIView *vLine;
@property (weak, nonatomic) IBOutlet UIButton *historyBtn;
@property (weak, nonatomic) IBOutlet UIButton *pendingBtn;
@property (nonatomic, strong) dispatch_group_t group;
@property (nonatomic, strong) dfhgwhruebvhrheyleapoccurrenceViewController *pendingVC;
@property (nonatomic, strong) dfhgwhruebvhrheyaltererroneousViewController *historyVC;
@end
@implementation dfhgwhruebvhrheydisplayblastViewController
- (dfhgwhruebvhrheyleapoccurrenceViewController *)pendingVC {
	if (_pendingVC == nil) {
		_pendingVC = (dfhgwhruebvhrheyleapoccurrenceViewController *)[UIStoryboard storyboard:@"Mine" withidentifier:@"pending"];
	}
	return _pendingVC;
}
- (dfhgwhruebvhrheyaltererroneousViewController *)historyVC {
	if (_historyVC == nil) {
		_historyVC = (dfhgwhruebvhrheyaltererroneousViewController *)[UIStoryboard storyboard:@"Mine" withidentifier:@"history"];
	}
	return _historyVC;
}
- (void)viewDidLoad {
    [super viewDidLoad];
	[self loadUI];
	AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
	if (delegate.status != AFNetworkReachabilityStatusNotReachable) {
		[self loadData];
	}
}
- (void)loadUI {
	[self configBackIcon:@"dhgfywegwygeydwcurvereciprocal"];
	self.navigationItem.title = @"Loan Record";
	self.navigationStyle = dhgfywegwygeydwreciprocaltransport;
	[self addChildViewController:self.pendingVC];
	[self addChildViewController:self.historyVC];
	[self.containerView addSubview:self.pendingVC.view];
	[self.containerView addSubview:self.historyVC.view];
}
- (void)loadData {
	__weak typeof(self) weakSelf = self;
	if (self.group == nil) {
		self.group = dispatch_group_create();
	}
	dispatch_group_enter(self.group);
	[self.pendingVC loadData:^{
		__strong typeof(weakSelf) strongSelf = weakSelf;
		dispatch_group_leave(strongSelf.group);
	}];
	dispatch_group_enter(self.group);
	[self.historyVC loadData:^{
		__strong typeof(weakSelf) strongSelf = weakSelf;
		dispatch_group_leave(strongSelf.group);
	}];
	[dfhgwhruebvhrheyoptionsaving.keyWindow startLoading];
	dispatch_group_notify(self.group, dispatch_get_main_queue(), ^{
		[dfhgwhruebvhrheyoptionsaving.keyWindow stopLoading];
	});
}
- (IBAction)recordBtnsClick:(UIButton *)sender {
	self.pendingBtn.selected = NO;
	self.historyBtn.selected = NO;
	self.pendingBtn.titleLabel.font = [UIFont regular:15];
	self.historyBtn.titleLabel.font = [UIFont regular:15];
	switch (sender.tag) {
		case 100: {
			self.pendingBtn.selected = YES;
			self.pendingBtn.titleLabel.font = [UIFont semiBold:15];
			[self .scrollIV setContentOffset:CGPointMake(0, 0) animated:YES];
		}
			break;
		case 200: {
			self.historyBtn.selected = YES;
			self.historyBtn.titleLabel.font = [UIFont semiBold:15];
			[self .scrollIV setContentOffset:CGPointMake(dhgfywegwygeydwdispositionvisualize, 0) animated:YES];
		}
			break;
		default:
			break;
	}
}
- (void)viewDidLayoutSubviews {
	[super viewDidLayoutSubviews];
	[self.pendingVC.view mas_makeConstraints:^(MASConstraintMaker *make) {
		make.top.left.bottom.equalTo(self.containerView);
		make.width.mas_equalTo(dhgfywegwygeydwdispositionvisualize);
	}];
	[self.historyVC.view mas_makeConstraints:^(MASConstraintMaker *make) {
		make.left.equalTo(self.pendingVC.view.mas_right);
		make.top.right.bottom.equalTo(self.containerView);
		make.width.equalTo(self.pendingVC.view);
	}];
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
	[self.vLine mas_updateConstraints:^(MASConstraintMaker *make) {
		make.centerX.equalTo(self.pendingBtn).offset(scrollView.contentOffset.x / 2);
	}];
}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
	self.pendingBtn.selected = NO;
	self.historyBtn.selected = NO;
	self.pendingBtn.titleLabel.font = [UIFont regular:15];
	self.historyBtn.titleLabel.font = [UIFont regular:15];
	if (scrollView.contentOffset.x == 0) {
		self.pendingBtn.selected = YES;
		self.pendingBtn.titleLabel.font = [UIFont semiBold:15];
	}else {
		self.historyBtn.selected = YES;
		self.historyBtn.titleLabel.font = [UIFont semiBold:15];
	}
}
@end
